package com.example.service;

import cn.hutool.core.util.ObjectUtil;
import com.example.common.enums.RoleEnum;
import com.example.entity.Account;
import com.example.entity.Record;
import com.example.mapper.RecordMapper;
import com.example.utils.TokenUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RecordService {
    @Autowired
    private RecordMapper recordMapper;

    public void add(Record record){
        Account currentUser = TokenUtils.getCurrentUser();//获取用户身份
        System.out.println(currentUser.getRole());

        if (currentUser.getRole().equals("ADMIN")) {
            Integer AdminId = currentUser.getId();
            System.out.println("done");
            if (ObjectUtil.isNotEmpty(AdminId)) {
                record.setAdminId(AdminId);
                recordMapper.add(record);
                System.out.println(record);
            }
        }

    }
    public PageInfo<Record> selectPage(Integer pageNum,Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<Record> records = recordMapper.selectAll();

        return PageInfo.of(records);
    }
    public void deleteBatch(List<Integer> ids) {
        for (Integer id : ids) {
            this.delete(id);
        }
    }
    public void delete(Integer id){
        recordMapper.delete(id);
    }
    public void update(Record record){
        recordMapper.update(record);
    }




}
